package com.bz.redis.controller;

import com.bz.dto.CartDto;
import com.bz.redis.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/redis/cart")
public class CartController {

    @Autowired
    private CartService cartService;

    /**
     * 将购物车缓存到redis中
     * @param cartDto
     */
    @RequestMapping("/insertCart")
    public void insertCart(@RequestBody CartDto cartDto){
        cartService.insertCart(cartDto);
    }

    /**
     * 根据用户ID查询用户购物车
     * @param userId
     * @return
     */
    @RequestMapping("/selectCartByUserId")
    public CartDto selectCartByUserId(@RequestParam Long userId){
        return cartService.selectCartByUserId(userId);
    }
}